package com.na.qwr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

/**
 * @Author: Qingwr
 * @Date: 2022/8/13 21:56
 * @Description 驱动类
 * 需求:求出每一个订单中成交金额最大的一笔交易
 * 订单编号      商品编号    金额
 * order_001	goods_001	100
 * order_001	goods_002	200
 * order_002	goods_003	300
 * order_002	goods_004	400
 * order_002	goods_005	500
 * order_003	goods_001	100
 */
public class JobMain {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //创建job
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration, "orderMax");

        //设置源文件路径
        job.setInputFormatClass(TextInputFormat.class);
        TextInputFormat.addInputPath(job, new Path(args[0]));

        //设置Mapper
        job.setMapperClass(OrderMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        //设置Reducer
        job.setReducerClass(OrderReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //设置输出路径
        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job, new Path(args[1]));

        //执行
        boolean b = job.waitForCompletion(true);
        System.out.println(b ? 0 : 1);
    }
}
